self.addEventListener('message', function (e) {
  console.log('worker启动')

  const { action, nodeId, nodeLookup } = e.data
  console.log(nodeLookup)

  if (action === 'getAllParentNodes') {
    const parents = getAllParentNodes(nodeId, nodeLookup)
    self.postMessage({ action: 'getAllParentNodes', parents })
    console.log('worker结束', parents)
  }
})

function getAllParentNodes(nodeId, nodeLookup) {
  const parents = []
  let currentNode = nodeLookup[nodeId]
  while (currentNode && currentNode.parentId !== null) {
    currentNode = nodeLookup[currentNode.parentId]
    if (currentNode) {
      parents.push(currentNode)
    }
  }
  return parents.reverse()
}
